//
//  BaseViewController.swift
//  iOSProjectExtensionSwift
//
//  Created by Apple on 2020/1/11.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit
import IQKeyboardManagerSwift
class BaseViewController: UIViewController, UIGestureRecognizerDelegate {
    //键盘辅助工具是否可以用--------默认可用，通过设置去规避可能出现的bug
    var enableAutoToolbar: Bool = true
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        self.tabBarController?.view.backgroundColor = .white
        self.navigationController?.setNavigationBarHidden(false, animated: true)
        //在NavigationController堆栈内的UIViewController可以支持右滑手势，即在屏幕左边一滑，屏幕就会返回。但是在自定义返回按钮这个手势就会失效
        self.navigationController?.interactivePopGestureRecognizer?.delegate = self
        
        /**
        *  去掉导航栏的横线（一条黑线）
        */
        let navigationBar = self.navigationController?.navigationBar
        navigationBar?.setBackgroundImage(UIImage.imageWithColor(color: .white), for: .any, barMetrics: .default)
        //设置返回按钮的颜色  在plist中添加 View controller-based status bar appearance=NO切记。
        navigationBar?.tintColor = .black
        //设置返回样式图片
        var image = UIImage(named: "loginBack-1")
        image = image?.withRenderingMode(.alwaysOriginal)
        navigationBar?.backIndicatorImage = image
        //自定义返回按钮
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 46, height: 44))
        let imageV = UIImageView(frame: CGRect(x: 0, y: 15, width: 46/2, height: 28/2))
        imageV.image = image?.withRenderingMode(.alwaysOriginal)
        view.addSubview(imageV)
        let tap = UITapGestureRecognizer(target: self, action: #selector(goLeftTOView))
        view.addGestureRecognizer(tap)
        let left = UIBarButtonItem(customView: view)
        self.navigationItem.leftBarButtonItem = left
        navigationBar?.barStyle = .default
        //添加头部的横线
        let headerLine = UILabel.createLineLabelWithFrame(frame: CGRect(x: 0, y: 0, width: DeviceWidth, height: kLineWitdth))
        self.view.addSubview(headerLine)
        headerLine.backgroundColor = .white
        headerLine.addShadowInViewPrivite()
        regestNetWoringIsValiable()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        IQKeyboardManager.shared.enableAutoToolbar = enableAutoToolbar
    }
    //注册网络变更为可用
    func regestNetWoringIsValiable() {
        NotificationCenter.default.addObserver(self, selector: #selector(netWorkingIsValiable), name: NSNotification.Name(rawValue: NET_WORKING), object: nil)
    }
    @objc func netWorkingIsValiable() {
        
    }
    @objc public func goLeftTOView() {
        self.navigationController?.popViewController(animated: true);
    }
    func goLoginWithViewController(viewController:UIViewController) {
        let login = LoginViewController()
        let loginNav = CCNavigationController.init(rootViewController: login)
        loginNav.navigationBar.isTranslucent = false;
        loginNav.modalTransitionStyle = .crossDissolve;
        loginNav.modalPresentationStyle = .fullScreen;
        viewController.present(loginNav, animated: true)
        UIView.setAnimationTransition(.flipFromLeft, for: login.view, cache: true)
//        UIView.transition(with: login.view, duration: 0.5, options: .transitionFlipFromLeft, animations: nil, completion: nil)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
